﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Icoders.MarketTracker.Web.Lib.Response.Services;

namespace Icoders.MarketTracker.Web.Controllers
{
    public class SyncMasterDataController : Controller
    {
        IPullMasterDataResponseBuilder _pullMasterDataResponseBuilder;
        private IObjectSerialzationHelper _coreObjectSerializationHelper;

        public SyncMasterDataController(IPullMasterDataResponseBuilder pullMasterDataResponseBuilder, IObjectSerialzationHelper coreObjectSerializationHelper)
        {
            _pullMasterDataResponseBuilder = pullMasterDataResponseBuilder;
            _coreObjectSerializationHelper = coreObjectSerializationHelper;
        }

        public ActionResult GetEntityMasterData(int applicationId, string entityName)
        {
            ContentResult result = new ContentResult();
            result.ContentType = "application/json";
            result.ContentEncoding = Encoding.UTF8;
            result.Content = null;
            try
            {
                var resp = _pullMasterDataResponseBuilder.GetMasterDataInfo(applicationId, entityName);
                result.Content = _coreObjectSerializationHelper.SerializeObjectToJSON(resp);
               // _log.InfoFormat("GetEntityMasterData - ccappid : {0} - entity name : {1} - result : {2} ", costCentreApplicationId, entityName, result.Content);
            }
            catch (Exception ex)
            {
                //_log.InfoFormat("ERROR - GetEntityMasterData for ccAppId {0} and entity {1}", costCentreApplicationId, entityName);
               // _log.Error(ex);
            }
            return result;
        }

    }
}
